/*
package com.ruoyi.web.core.config;

import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.FileInputStream;
import java.io.IOException;
import java.security.PrivateKey;

@Configuration
public class WxPayConfigs {

    @Value("${wechat.pay.merchant-id}")
    private String merchantId;

    @Value("${wechat.pay.private-key-path}")
    private String privateKeyPath; // 私钥路径（apiclient_key.pem）

    @Value("${wechat.pay.api-v3-key}")
    private String apiV3Key;
    @ConditionalOnMissingBean
    @Bean
    public JsapiService jsapiService() throws IOException {
        try {
            // 加载商户私钥
            PrivateKey privateKey = PemUtil.loadPrivateKey(
                    new FileInputStream(privateKeyPath)
            );
            // 初始化配置
            Config config = new RSAAutoCertificateConfig.Builder()
                    .merchantId(merchantId)
                    .privateKey(privateKey)
                    .apiV3Key(apiV3Key)
                    .build();
            // 创建小程序支付服务
            return new JsapiService.Builder().config(config).build();
        }catch (Exception e){
            System.out.println(e);
        }
        return null;
    }
}*/
